package com.cxhc.system.service.cockpit.impl;

import com.cxhc.system.domain.cockpit.ViidVehicle;
import com.cxhc.system.mapper.cockpit.ViidVehicleMapper;
import com.cxhc.system.service.cockpit.IViidVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ViidVehicleServiceImpl implements IViidVehicleService {


    /** 查询影像前缀 */
    @Value("${image.url}")
    private String URL;

    @Autowired
    private ViidVehicleMapper viidVehicleMapper;

    @Override
    public List<ViidVehicle> queryVehicle() {
        List<ViidVehicle> viidVehicles = viidVehicleMapper.queryVehicleList();
        for (ViidVehicle viidVehicle : viidVehicles) {
            viidVehicle.setStorageUrl1(URL + viidVehicle.getStorageUrl1());
        }
        return viidVehicles;
    }

    @Override
    public Map<String, String> queryVehicleCount(String date) {
        List<ViidVehicle> viidVehicles = viidVehicleMapper.queryVehicleListByDate(date);
        Map<String,String> mapRes = new HashMap<>();
        Map<String, List<ViidVehicle>> collect = viidVehicles.stream().
                collect(Collectors.groupingBy(ViidVehicle::getDirection));
        //今日车流总和
        int sumToday = 0;
        int inCar = 0;
        for (String s : collect.keySet()) {
            sumToday += collect.get(s).size();
            if (s.equals("In") || s.equals("0")){
                inCar += collect.get(s).size();
            }else{
                inCar -= collect.get(s).size();
            }
        }

        mapRes.put("sumToday",String.valueOf(sumToday));
        mapRes.put("inCar",String.valueOf(inCar));

        return mapRes;
    }
}
